package com.andy;


import com.andy.web.MySpringServletContainerInitializer;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletRegistration;
import java.util.ServiceLoader;

public class SpringApplication {

    public static void run() throws LifecycleException {
        Tomcat tomcat = new Tomcat();
        String base = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        tomcat.setPort(8080);
        ServiceLoader<ServletContainerInitializer> load = ServiceLoader.load(ServletContainerInitializer.class);
        Context context = tomcat.addContext("/demo",base);
        for (ServletContainerInitializer servletContainerInitializer : load) {
            context.addServletContainerInitializer(servletContainerInitializer,null);
        }
        tomcat.start();
        tomcat.getServer().await();
    }



}
